pow
Class AES

java.lang.Object
  extended by pow.AES

public class AES
extends java.lang.Object

implements AES encryption and decryption algorithms see @link http://java.sun.com/developer/technicalArticles/Security/AES/AES_v1.html see @link http://stackoverflow.com/questions/992019/java-256bit-aes-encryption


Constructor Summary
AES()
          construct a cipher with a generated 128 bits key
AES(byte[] key, byte[] iv)
          construct a cipher from a key and a parameter array usefull to create a remote decryption cypher
AES(java.lang.String password)
          construct a cipher from an user specified key
 
Method Summary
 byte[] decrypt(byte[] msg)
          decrypt a byte array with AES algorithm see @link org.apache.commons.codec.binary.Hex to convert byte Array into hexString
 byte[] encrypt(byte[] msg)
          encrypt a byte array with AES algorithm
 byte[] getKey()
          get the cipher key
 byte[] getParamsEncrypt()
          get the init parameter of the cipher object in order to initialyse correctly a remote cipher
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AES

public AES()
    throws java.security.NoSuchAlgorithmException,
           javax.crypto.NoSuchPaddingException,
           java.security.InvalidKeyException,
           java.security.spec.InvalidParameterSpecException,
           java.security.InvalidAlgorithmParameterException
construct a cipher with a generated 128 bits key

Throws:
java.security.spec.InvalidParameterSpecException
java.security.InvalidAlgorithmParameterException
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException

AES

public AES(java.lang.String password)
    throws java.security.NoSuchAlgorithmException,
           javax.crypto.NoSuchPaddingException,
           java.security.InvalidKeyException,
           java.security.spec.InvalidParameterSpecException,
           java.security.InvalidAlgorithmParameterException,
           java.security.spec.InvalidKeySpecException
construct a cipher from an user specified key

Parameters:
password - a string representing the user key
Throws:
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
java.security.spec.InvalidParameterSpecException
java.security.InvalidAlgorithmParameterException
java.security.spec.InvalidKeySpecException

AES

public AES(byte[] key,
           byte[] iv)
    throws java.security.InvalidKeyException,
           java.security.InvalidAlgorithmParameterException,
           java.security.NoSuchAlgorithmException,
           javax.crypto.NoSuchPaddingException
construct a cipher from a key and a parameter array usefull to create a remote decryption cypher

Parameters:
key - the key in array byte format
iv - parameter of the cipher
Throws:
java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
Method Detail

getParamsEncrypt

public byte[] getParamsEncrypt()
                        throws java.security.spec.InvalidParameterSpecException
get the init parameter of the cipher object in order to initialyse correctly a remote cipher

Throws:
java.security.spec.InvalidParameterSpecException

getKey

public byte[] getKey()
get the cipher key

Returns:
the cipher key in byte array

encrypt

public byte[] encrypt(byte[] msg)
               throws java.io.IOException,
                      javax.crypto.IllegalBlockSizeException,
                      javax.crypto.BadPaddingException
encrypt a byte array with AES algorithm

Parameters:
msg -
Returns:
a byte array containing the ciphered data
Throws:
java.io.IOException
javax.crypto.BadPaddingException
javax.crypto.IllegalBlockSizeException
See Also:
to convert byte Array into hexString

decrypt

public byte[] decrypt(byte[] msg)
               throws java.io.IOException,
                      javax.crypto.IllegalBlockSizeException,
                      javax.crypto.BadPaddingException
decrypt a byte array with AES algorithm see @link org.apache.commons.codec.binary.Hex to convert byte Array into hexString

Parameters:
msg - the msg to decrypt
Returns:
the message decrypted
Throws:
java.io.IOException
javax.crypto.BadPaddingException
javax.crypto.IllegalBlockSizeException